﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ForecastPostInfo : System.Web.UI.Page
{
    protected List<Model.UsersAccount> userAccount = null;
    protected List<Model.ForecastPost> tzlist = null;
    protected decimal winmonenyTotal, jiangjin2 = 0;
    protected string content,id,title,time,userName,login = "";
    protected int pageview, totalCount = 0;
    protected List<Model.NewsSite>  forecastNew = null;
    protected List<Model.ForecastComment> forecastList = null;
    protected void Page_Load(object sender, EventArgs e)
    {
          id = Request["id"].ToString();
          int totalCount2 = 0;
          int totalcount = 0;
          int totalCount1 = 0;
          tzlist = BLL.ForecastPost.GetPageListBysql(0, 6, "", out totalCount1);
           userAccount = BLL.UsersAccount.getList(0, int.MaxValue, out totalCount2);
           foreach (Model.UsersAccount user in userAccount)
           {
                winmonenyTotal += user.winTotal;
           }
           jiangjin2 = Convert.ToDecimal(winmonenyTotal) / 100000000;
        forecastNew = BLL.NewsSite.GetPageList_Where(0, 6, 5, out totalcount);
        BindContent();
            BindComment();
        InsertPageview();
    }
    private void BindContent()
    {
        if(BLL.CMember.UserLoginInfo()!=null)
        {
            login = BLL.CMember.UserLoginInfo().nickname;
        }
        string sql = "select * from ForecastPost  where id=" + id;
        Model.ForecastPost forecastPost = new Model.ForecastPost();
        forecastPost = BLL.ForecastPost.NewsTopOne(sql);
        if (forecastPost != null)
        {
            content = forecastPost.Content;
            title = forecastPost.Title;
            time = forecastPost.AddTime.ToString("yyyy-MM-dd HH:mm");
            userName = SelectName(forecastPost.UserID);
            pageview = forecastPost.Pageview+1;
        }
    }
    private void BindComment()
    {
        PagedDataSource pds = new PagedDataSource();
        string sql = "  postid=" + id+" and ";
        forecastList = BLL.ForecastComment.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, sql + " 1=1 ", out totalCount);
        if (forecastList != null && forecastList.Count > 0)
        {
            AspNetPager1.RecordCount = totalCount;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        }
    }
    /// <summary>
    /// 浏览量加1
    /// </summary>
    private void InsertPageview()
    {
        Model.ForecastPost fp = BLL.ForecastPost.GetModelByuser_id(Convert.ToInt32(id));
        fp.Pageview = pageview;
        long flag = BLL.ForecastPost.Update(fp);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindComment();
    }
     public string SelectName(object Uid)
    {
        Model.CMember cm = BLL.CMember.GetModel(Convert.ToInt32(Uid));
        if (cm != null)
        {
            return cm.nickname;//用户真实姓名
        }
        else
        {
            return "***";
        }
    }
    public string GetPhoto(object Uid)
    {
        Model.CMember cm = BLL.CMember.GetModel(Convert.ToInt32(Uid));
        if (cm != null)
        {
              return cm.photo;//用户真实姓名
        }
        else
        {
            return "";
        }
    }
}